from django.contrib import admin
from .models import TranslateToHex


@admin.register(TranslateToHex)
class TranslateToHexAdmin(admin.ModelAdmin):
    list_display = ('original_string_short', 'hex_string_short', 'created_at')
    list_filter = ('created_at',)
    search_fields = ('original_string', 'hex_string')

    def original_string_short(self, obj):
        return obj.original_string[:50] + '...' if len(obj.original_string) > 50 else obj.original_string

    original_string_short.short_description = '原始字符串'

    def hex_string_short(self, obj):
        return obj.hex_string[:50] + '...' if len(obj.hex_string) > 50 else obj.hex_string

    hex_string_short.short_description = '十六进制字符串'